#coding=utf-8
#author:u'王健'
#Date: 13-9-25
#Time: 下午11:30
from tools.page import Page

__author__ = u'王健'


class BlogIndex(Page):
    '''
    博客首页
    '''

    def get(self, *args):
        self.render('template/empty.html', {'content': u'这是博客'})


class AddPage(Page):
    '''
    博客首页
    '''

    def get(self, *args):
        a = self.request.get('a')#获取参数a的值
        b = self.request.get('b')
        c = self.request.get('c')

        d = int(a) + int(b) + int(c)

        self.render('template/empty.html', {'content': d})


class CounterPage(Page):
    '''
    博客首页
    '''

    def get(self, *args):
        self.render('template/counter.html', {'title': u'这里是表单', 'desc': u'模拟一个计算机'})

    def post(self):
        first = self.request.get('first')#获取参数first的值
        second = self.request.get('second')#获取参数second的值
        type = self.request.get('type')#获取参数type的值

        if not first or not second or not type:
            self.render('template/counter.html',
                        {'title': u'表单学习', 'desc': u'模拟一个计算器', 'first': first, 'second': second, 'type': type,
                         'result': u'错误，请填写必要的值。'})
            return
        if type == '+':
            result = int(first) + int(second)
        elif type == '-':
            result = int(first) - int(second)
        elif type == '*':
            result = int(first) * int(second)
        elif type == '/':
            result = int(first) / int(second)
        else:
            result = u'运算法则错误'
        self.render('template/counter.html',
                    {'title': u'表单学习', 'desc': u'模拟一个计算器', 'first': first, 'second': second, 'type': type,
                     'result': result})

